<?php
namespace app\walletyhbbadmin\controller;
use Think\Db;
require_once (APP_PATH .'api/FinanceApi.php');
class Currency extends AdminBase {
	protected $currency;
	public function _initialize(){
		parent::_initialize();
	}
	//空操作
	public function _empty(){
		header("HTTP/1.0 404 Not Found");
		$this->display('Public:404');
	}
	
	/**
	 * 提现记录
	 */
	public function tibi_index()
    {
        $res = DB::name('withdrawals')->select();
        foreach($res as $k=>$v)
        {
            $res[$k]['user_id'] = DB::name('users')->where('user_id',$v['user_id'])->value('nickname');
        }
        $this->assign('list',$res);
        return $this->fetch('currency/tibi_index');
    }


    /**
     * 删除提现记录
     */
    public function deletes()
    {
        $id = input('id');
//        $jilu['status'] = 3;
        if (Db::name('withdrawals')->where('id',$id)->delete($jilu))
        {
            $this->success('删除成功!','/walletyhbbadmin/Currency/tibi_index');
        }else{
            $this->error('删除失败');
        }
    }
	/**
	 * 充值审核
	 */
	public function shenhe()
    {
        $id = input('id');
        $data['status'] = 1;
        $bool = DB::name('withdrawals')->where('id',$id)->update($data);
        $arr = DB::name('withdrawals')->where('id',$id)->find();
//        $Finance = new \FinanceApi();
//        $re[]=$Finance->addFinance($arr['user_id'], 1, "提现".$arr['num'].",到". $arr['bank_id'].'尾号'.substr($arr['bank_id'],-4),'2',$arr['num'],1);
        if($bool)
        {
            $this->success('审核通过');
        }
    }

	//驳回审核
    public function bohui()
    {
        $id = input('id');
        $data['status'] = -1;
        $bool = DB::name('withdrawals')->where('id',$id)->update($data);
        if($bool)
        {
            $this->error('审核驳回');
        }
    }

    /*
     * 提现说明页面和修改
     */
    public function withdrawals(){
        $type = input('type');
        if($type==1){    //进入提现说明页面
            $info = Db::name('config')->where('name','withdrawals_info')->find();
            $this->assign('content',$info['value']);
            return $this->fetch();
        }else{    //修改提现说明提交
            $up['value'] = input('content','','html_entity_decode');
            $res = Db::name('config')->where('name','withdrawals_info')->update($up);
            if($res!==false){
                $this->success('修改成功',U('Currency/tibi_index'));
            }else{
                $this->error('操作失败');
            }
        }
    }








}